// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    date: "",
    int: null,
    flag: undefined,
    imgList: ["cloud://test-clould-1-0gd3de4ve3870b4d.7465-test-clould-1-0gd3de4ve3870b4d-1258129083/images/banner.jpg"],
    lastTime: 0,
    cmosWidth: 0,
    pxWidth: 0,
    aperture: 0,
    f: 0,
  },
  getF(e) {
    this.setData({
      f: e.detail.value
    })
  },
  getComsWidth(e) {
    this.setData({
      cmosWidth: e.detail.value
    })
  },
  getPxWidth(e) {
    this.setData({
      pxWidth: e.detail.value
    })
  },
  getAperture(e) {
    this.setData({
      aperture: e.detail.value
    })
  },

  toCau() {
    const {
      cmosWidth,
      pxWidth,
      f,
      aperture
    } = this.data;
    const P = (cmosWidth / pxWidth) * 1000;
    const time = ((35 * aperture + 30 * P) / f).toFixed(2);
    console.log(time);

    if (isNaN(time)) {
      wx.showToast({
        title: '输入有误,注意检查!',
        icon: "none"
      })
      return;
    }
    this.setData({
      lastTime: time
    })
  },

  viewimg() {
    wx.previewImage({
      current: 'https://7465-test-clould-1-0gd3de4ve3870b4d-1258129083.tcb.qcloud.la/images/f72bdcd93effffe401974cc07b96a7f.jpg', // 当前显示图片的http链接
      urls: ["https://7465-test-clould-1-0gd3de4ve3870b4d-1258129083.tcb.qcloud.la/images/f72bdcd93effffe401974cc07b96a7f.jpg"] // 需要预览的图片http链接列表
    })
  },
  // npf

  nav2details() {
    wx.navigateTo({
      url: '../show/show',
    })
  },
  setMode() {
    let flag = wx.getStorageSync('flag');
    if (flag == "full") {
      wx.setNavigationBarTitle({
        title: '电子健康码'
      })
      clearInterval(this.int)
    } else {
      this.initTime()
      this.startTime()
      wx.setNavigationBarTitle({
        title: 'npf计算'
      })

    }
    this.setData({
      flag
    })
  },
  onLoad() {
    wx.showLoading({})
    setTimeout(() => {
      wx.hideLoading({
        success: (res) => {},
      })
    }, 500)
    let flag = wx.getStorageSync('flag')
    if (flag == "full") {
      this.nav2details()
    }


  },
  onShow() {
    this.setMode();
  },
  initTime() {
    this.date = this.newTime()
  },
  startTime() {
    this.int = setInterval(() => {
      this.setData({
        date: this.newTime(),
      })
    }, 1000)
  },
  newTime() {
    let time = new Date();
    let Y = time.getFullYear();
    let M = time.getMonth() + 1;
    let d = time.getDate();
    let h = time.getHours() >= 10 ? time.getHours() : "0" + time.getHours();
    let m = time.getMinutes() >= 10 ? time.getMinutes() : "0" + time.getMinutes();
    let s = time.getSeconds() >= 10 ? time.getSeconds() : "0" + time.getSeconds();
    return `${Y}-${M}-${d} ${h}:${m}:${s}`
  },

  nav2set() {
    wx.navigateTo({
      url: '../setting/setting',
    })
  },

})